package com.zl.cms.util;

import java.util.Date;
import java.util.List;

import com.zl.cms.model.*;
import junit.framework.Assert;

/**
 * User: zl email:c3tc3tc3t@126.com Date: 14-1-14 Time: 下午2:26 增加了比较角色，组的方法
 */
public class EntitiesHelper {
  private static User baseUser = new User(1, "admin1", "admin123", "superr", "admin@126.com",
      "120", 1);

  private static Role baseRole = new Role(1, "网站的管理员", RoleType.ROLE_ADMIN);
  private static Group baseGroup = new Group(1, "财务处", "负责财务部门网页");

  public static void assertUser(User expected, User actual) {
    Assert.assertNotNull(actual);
    Assert.assertEquals(expected.getId(), actual.getId());
    Assert.assertEquals(expected.getUsername(), actual.getUsername());
    Assert.assertEquals(expected.getNickname(), actual.getNickname());
/*    Assert.assertEquals(expected.getPassword(), actual.getPassword());*/
    Assert.assertEquals(expected.getEmail(), actual.getEmail());
    Assert.assertEquals(expected.getPhone(), actual.getPhone());
    Assert.assertEquals(expected.getStatus(), actual.getStatus());

  }

  public static void assertUsers(List<User> expected, List<User> actuals) {
    for (int i = 0; i < expected.size(); i++) {
      User eu = expected.get(i);
      User au = actuals.get(i);
      assertUser(eu, au);
    }
  }

  public static void assertUser(User actual) {
    assertUser(baseUser, actual);
  }

	public static void assertObjects(List<?> expected,List<?> actuals) {
		for(int i=0;i<expected.size();i++) {
			Object eo = expected.get(i);
			Object ao = actuals.get(i);
			Assert.assertEquals(eo, ao);
		}
	}

	public static void assertRole(Role expected, Role actual) {
    Assert.assertNotNull(actual);
    Assert.assertEquals(expected.getId(), actual.getId());
    Assert.assertEquals(expected.getName(), actual.getName());
    Assert.assertEquals(expected.getRoleType(), actual.getRoleType());
  }

  public static void assertRoles(List<Role> expected, List<Role> actuals) {
    for (int i = 0; i < expected.size(); i++) {
      Role eu = expected.get(i);
      Role au = actuals.get(i);
      assertRole(eu, au);
    }
  }

  public static void assertRole(Role actual) {
    assertRole(baseRole, actual);
  }

  public static void assertGroup(Group expected, Group actual) {
    Assert.assertNotNull(actual);
    Assert.assertEquals(expected.getId(), actual.getId());
    Assert.assertEquals(expected.getName(), actual.getName());
    Assert.assertEquals(expected.getDescr(), actual.getDescr());
  }

  public static void assertGroups(List<Group> expected, List<Group> actuals) {
    for (int i = 0; i < expected.size(); i++) {
      Group eu = expected.get(i);
      Group au = actuals.get(i);
      assertGroup(eu, au);
    }
  }

  public static void assertGroup(Group actual) {
    assertGroup(baseGroup, actual);
  }

  public static void assertUserGroup(UserGroup expected, UserGroup actual) {
    Assert.assertNotNull(actual);
    Assert.assertEquals(expected.getId(), actual.getId());
    assertUser(expected.getUser(), actual.getUser());
    assertGroup(expected.getGroup(), actual.getGroup());
  }

  public static void assertUserRole(UserRole expected, UserRole actual) {
    Assert.assertNotNull(actual);
    Assert.assertEquals(expected.getId(), actual.getId());
    assertUser(expected.getUser(), actual.getUser());
    assertRole(expected.getRole(), actual.getRole());
  }

  public static void assertChannel(Channel expected, Channel actual) {
    Assert.assertNotNull(actual);
    Assert.assertEquals(expected.getId(), actual.getId());
    Assert.assertEquals(expected.getName(), actual.getName());
  }

  public static void assertChannelTree(ChannelTree expected, ChannelTree actual) {
    Assert.assertNotNull(actual);
    Assert.assertEquals(expected.getId(), actual.getId());
    Assert.assertEquals(expected.getName(), actual.getName());
    Assert.assertEquals(expected.getPid(), actual.getPid());
  }

  public static void assertListChannel(List<Channel> expected, List<Channel> actual) {
    Assert.assertNotNull(actual);
    for (int i = 0; i < expected.size(); i++) {
      Channel expected_channel = expected.get(i);
      Channel actual_channel = actual.get(i);
      assertChannel(expected_channel, actual_channel);
    }
  }

  public static void assertListChannelTree(List<ChannelTree> expected, List<ChannelTree> actual) {
    Assert.assertNotNull(actual);
    for (int i = 0; i < expected.size(); i++) {
      ChannelTree expected_channel = expected.get(i);
      ChannelTree actual_channel = actual.get(i);
      assertChannelTree(expected_channel, actual_channel);
    }
  }

  public static void assertGroupChannel(GroupChannel expected, GroupChannel actual) {
    Assert.assertNotNull(actual);
    Assert.assertEquals(expected.getId(), actual.getId());
    Assert.assertEquals(expected.getGroup().getId(), actual.getChannel().getId());
    Assert.assertEquals(expected.getChannel().getId(), actual.getChannel().getId());
  }
}
